package com.example.ssm.controller;

import com.example.ssm.utils.FileLocalUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/file")
public class FileController {
    /**
     * 前端直传文件，成功即返回存储路径
     */
    @PostMapping("/upload")
    public ResponseEntity<Map<String, Object>> upload(@RequestParam("file") MultipartFile file) {
        String path = FileLocalUtil.save(file);
        return ResponseEntity.ok(Map.of(
                "code", 200,
                "msg", "success",
                "path", path        // 前端直接拿这个字段即可
        ));
    }
}
